home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Performance Co-Pilot 1.3
/
SGI Performance Co-Pilot 1.3.iso
/
dist
/
pcp.idb
/
usr
/
pcp
/
lib
/
pmie-common.z
/
pmie-common
Wrap
Text File
|
1997-04-03
|
4KB
|
156 lines
#!/bin/sh
#
# WARNING: BEGIN
# DO NOT MODIFY THIS SCRIPT. YOUR CHANGES MAY BE LOST!
#
# This script was installed as part of the Performance Co-Pilot
# software installation.
#
# WARNING: END
#
# Copyright 1995, Silicon Graphics, Inc.
# ALL RIGHTS RESERVED
#
# UNPUBLISHED -- Rights reserved under the copyright laws of the United
# States. Use of a copyright notice is precautionary only and does not
# imply publication or disclosure.
#
# U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND:
# Use, duplication or disclosure by the Government is subject to restrictions
# as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights
# in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or
# in similar or successor clauses in the FAR, or the DOD or NASA FAR
# Supplement. Contractor/manufacturer is Silicon Graphics, Inc.,
# 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311.
#
# THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY
# INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION,
# DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY
# PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON
# GRAPHICS, INC.
#
# common /bin/sh procedures for standard pmie action scripts
#
# $Id: common.sh,v 2.1 1997/03/26 03:09:56 kenmcd Exp $
PMIEDIR=/tmp/pmie # control and lock files live here, directory is
# made writeable by everyone
LOCK=$PMIEDIR/lock # lock file
LOCKWAIT=5 # wait this long for the lock, then give up
# control files ... copy $MASTER to $CONTROL if required, and make
# $CONTROL writeable by everyone
MASTER=/var/pcp/config/pmie/control.master
CONTROL=$PMIEDIR/control
# __init
# initialize the temporary directory
__init()
{
if [ ! -d $PMIEDIR ]
then
mkdir $PMIEDIR
chmod 777 $PMIEDIR
fi
if [ ! -f $CONTROL ]
then
cp $MASTER $CONTROL
chmod 666 $CONTROL
fi
}
# _lock
# return 0 if lock acquired, else 1
#
_lock()
{
__init
i=0
while [ $i -lt $LOCKWAIT ]
do
if /usr/pcp/bin/pmlock $LOCK
then
return 0
fi
sleep 1
i=`expr $i + 1`
done
return 1
}
# _unlock
# unilaterally unlock, be removing the file
#
_unlock()
{
rm -f $LOCK
}
# _ok action-name
# check if action may proceed
#
_ok()
{
__init
mintime=""
eval `nawk <$CONTROL '
$1 == "'"$1"'" { print "mintime=" $2 " maxconcur=" $3 " laststamp=" $4 }'`
# if no entry in the control file, then no restrictions
[ "X$mintime" = "X" ] && return 0
if [ "X$mintime" != X- ]
then
# minimum time between invocations specified
check=`pmdate -${mintime}S %y%m%d%H%M%S`
# paranoia, in case file may have been corrupted
[ "X$laststamp" = X ] && laststamp=000000000000
if [ "$check" -lt "$laststamp" ]
then
# too soon
return 1
fi
fi
if [ "X$maxconcur" != X- ]
then
# maximum number of concurrent invocations specified
concur=`ps -ef \
| sed -e 's/ [0-2][0-9]:[0-5][0-9]:[0-5][0-9] / To Day /' \
| nawk '
$9 ~ /\/'"$1"'$/ || $9 == "'"$1"'" { print; next }
$9 ~ /sh$/ && ( $10 ~ /\/'"$1"'$/ || $10 == "'"$1"'" ) { print; next }
$9 ~ /sh$/ && $10 ~ /^-/ \
&& ( $11 ~ /\/'"$1"'$/ || $11 == "'"$1"'" ) { print; next }' \
| wc -l`
if [ "$concur" -gt "$maxconcur" ]
then
# too many
return 1
fi
fi
return 0
}
# _stamp action-name
# update date and time stamp, if required
#
_stamp()
{
__init
mintime=""
eval `nawk <$CONTROL '
$1 == "'"$1"'" { print "mintime=" $2 " maxconcur=" $3 " laststamp=" $4 }'`
# if no entry in the control file, then nothing to update
[ "X$mintime" = "X" ] && return
if [ "X$mintime" != X- ]
then
# minimum time between invocations specified, so update
now=`pmdate +0S %y%m%d%H%M%S`
nawk <$CONTROL >$CONTROL.new '
$1 == "'"$1"'" { print $1 " " $2 " " $3 " '"$now"'"; next }
{ print }'
mv $CONTROL.new $CONTROL
chmod 666 $CONTROL
fi
}